﻿$(function () {
    //获取课程列表
    function getList() {
        $.ajax("/api/course/getList", {method:'POST',dataType:'json'}).done(function (list) {
            $("#tt").autoTable({
                data: list,
                header: [
                    [{ title: '#', span: [1, 1] }, { title: '课程题目', span: [1, 1] }, { title: '讲师', span: [1, 1] }, { title: '开课时间', span: [1, 1] }, { title: '课时', span: [1, 1] }, { title: '地点', span: [1, 1] }, { title: '#', span: [1, 1] }]
                ],
                headerFields: ["TITLE", "AUTHOR", "KSSJ", "YJSC", "SKDD", "BZ"],
                keydataOnRow: ['ID'],
                columns: {
                    KSSJ: {
                        formator: function (v) {
                            var d = new Date(v);
                            return $.auto.frmDate(d, 'yyyy-MM-dd hh:mm');
                        }
                    },
                    BZ: {
                        formator: function (v, r) {
                            return `<button type="button" class="btn btn-success">开始听课</button>
<button type="button" class="btn btn-danger btnGl">课程管理</button>`;
                        }
                    }
                },
                isRownumber: true,
                isFooter: false,
                selectMode: AUTO.SelectMode.NONE,
            });
        });
    }
    getList();
    //点击讲课管理
    $("#tt").on("click", ".btnGl", function () {
        var id = $(this).parents("tr").data('id');
        $("#ID").val(id);
        $("#pwd").val('');
        $(".glBtn").attr("disabled", "disabled");
        $(".divGljm").dialog({ title: "管理界面",area: ['600px', '200px']});
    });
    //确认密码
    $("#btnQRMM").click(function () {
        $.ajax("/api/course/qrmm", {
            data: {
                id: $("#ID").val(), pwd: $("#pwd").val()
            }, method: 'POST', dataType: 'json'
        }).done(function (ret) {
            ret == 1 ? $(".glBtn").removeAttr("disabled"):$.auto.alert('错误','密码错误！');
        });
        return false;
    });
    //点击管理中的三个按钮时
    $(".glBtn").on("click", function () {
        var id = $("#ID").val(), pwd = $("#pwd").val();
        var lb = $(this).data('lb');
        if (lb == 'bj') {
            window.open(`/home/courseAdd?id=${id}&p=${pwd}`);
        }
    });

});